<?php
class role{
	protected $id,$name;
	
	const ADMIN = "admin";
	const CLIENT = "client";
	const AGENT = "agent";
	
	function __construct($id,$name){
		$this->id = $id;
		$this->name = $name;
	}
	
	public function getId(){
		return $this->id;
	}

	public function getName(){
		return $this->name;	
	}

	public function isAdmin(){
		if($this->name == self::ADMIN){
			return 1;		
		}else{
			return 0;	
		}
	}
	public function isClient(){
		if($this->name == self::CLIENT){
			return 1;		
		}else{
			return 0;	
		}		
		
	}
	public function isAgent(){
		if($this->name == self::AGENT){
			return 1;		
		}else{
			return 0;	
		}	
	}

	public static function getRoleByName($name){
		$conn = new dbmodifier();
		$name = $conn->db_connection->real_escape_string($name);
		$query = "SELECT * FROM ROLE WHERE name='".$name."'";
		$result = $conn->updateSQL($query);
		$conn->execute();
		$row = $result->fetch_array(MYSQLI_ASSOC);
		$var = new role($row['id'],$row['name']);		
		return $var;	

	}

	public static function getRoleById($id){
		$conn = new dbmodifier();
		$id = $conn->db_connection->real_escape_string($id);
		$query = "SELECT * FROM ROLE WHERE id='".$id."'";
		$result = $conn->updateSQL($query);
		$conn->execute();
		$row = $result->fetch_array(MYSQLI_ASSOC);
		$var = new role($row['id'],$row['name']);		
		return $var;	

	}
}
?>
